import axios from 'axios';
import { baseURL } from '../utils/http.js'; // 引入基础URL


export const getCartByUserId = (userid) => {
    console.log(`获取用户购物车地址${baseURL}/cart/getCartByUserId?userid=${userid}`); // 更新为正确的URL
    return axios.get(`${baseURL}/cart/getCartByUserId?userid=${userid}`);
};

//cart对象包含userid,productid,quantity
export const addProductToCart = (cart) => {
    console.log(`添加商品到购物车地址${baseURL}/cart/addProductToCart`); // 更新为正确的URL
    return axios.post(`${baseURL}/cart/addProductToCart`, cart);
};


export const deleteProductFromCart = (userid, productid) => {
    console.log(`删除商品地址${baseURL}/cart/deleteProductFromCart?userid=${userid}&productid=${productid}`); // 更新为正确的URL
    return axios.delete(`${baseURL}/cart/deleteProductFromCart?userid=${userid}&productid=${productid}`);
};

export const clearCartByUserId = (userid) => {
    console.log(`清空购物车地址${baseURL}/cart/clearCartByUserId?userid=${userid}`); // 更新为正确的URL
    return axios.delete(`${baseURL}/cart/clearCartByUserId?userid=${userid}`);
};


export const updateCartItemQuantity = (userid, productid, quantity) => {
    console.log(`修改购物车商品数量地址${baseURL}/cart/updateCartItemQuantity?userid=${userid}&productid=${productid}&quantity=${quantity}`); // 更新为正确的URL
    return axios.put(`${baseURL}/cart/updateCartItemQuantity?userid=${userid}&productid=${productid}&quantity=${quantity}`);
}




